package com.school.studentmanager.respository;

import com.school.studentmanager.model.StudentEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Administrator on 2016/6/14.
 */

@Repository
public interface StudentRepository extends JpaRepository<StudentEntity, Integer> {

    @Modifying      // 说明该方法是修改操作
    @Transactional  //

    // 定义查询
    // @Param注解用于提取参数
    @Query("update StudentEntity us set us.username=:qNickname, us.password=:qPassword where us.id=:qId")
    void updateUser(@Param("qNickname") String username, @Param("qPassword") String password, @Param("qId") Integer id);


    /**
     * 根据名称模糊查询
     * @param query
     * @return
     */
    @Query("select se from StudentEntity se where se.username like :qName")
    StudentEntity searchWithLike(@Param("qName") String query);
}
